new Vue({
  el: '#app',
  data() {
    return {
      rules:{
        Interest_Rate:[{required: true, message: '请选择利息率', trigger: 'change'}],
      },
      form: {
        Order_Financing_Contract_SerialNumber:'',
        Order_Financing_SerialNumber:'',
        Order_Financing_Name:'',
        Order_Financing_Phone:'',
        Group_Purchasing_SerialNumber:'',
        Starting_Quantity:'',
        Unit_Quantity:'',
        Repayment_Date:'',
        Order_Financing_Quantity:'',
        Quantity_Remain:'',
        Unit_Price:'',
        Interest_Rate:'',
        Start_Date:'',
        End_Date:'',
        Enterprise_Info_SerialNumber:'',
      },
      data:{},
      Enterprise_Name:'',
      loading:false
    }
  },
  mounted() {
    const order_financing_info = sessionStorage.getItem("order_financing_info")
    this.getData(JSON.parse(order_financing_info))
  },
  methods: {
    getData(obj){
      const _this = this;
      this.form.Order_Financing_SerialNumber = obj.Order_Financing_SerialNumber
      this.form.Order_Financing_Name = obj.Order_Financing_Name
      this.form.Order_Financing_Phone = obj.Order_Financing_Phone
      this.form.Group_Purchasing_SerialNumber = obj.Group_Purchasing_SerialNumber
      this.form.Repayment_Date = obj.Repayment_Date
      this.form.Starting_Quantity = obj.Starting_Quantity
      this.form.Unit_Quantity = obj.Unit_Quantity
      this.form.Order_Financing_Quantity = obj.Order_Financing_Quantity
      this.form.Quantity_Remain = obj.Order_Financing_Quantity
      this.form.Unit_Price = obj.Unit_Price
      this.form.Enterprise_Info_SerialNumber = obj.Enterprise_Info_SerialNumber
      this.Enterprise_Name =  obj.Enterprise_Name
      $.ajax({
        url: DomainName + '/GoodsInquiryKeyOriginal',
        type: 'POST',
        data:{
          Data:'order_financing_info',
          Primary_Key:obj.Order_Financing_SerialNumber,
          Primary_Key_Name:'Order_Financing_SerialNumber'
        },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '1'
            _this.data = res[0]
          }
        },
      })
    },
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          let obj = {
            Order_Financing_Log_SerialNumber:'',
            Order_Financing_SerialNumber:this.form.Order_Financing_SerialNumber,
            Operate:'1',
            TIME:getYMDHMSDate(),
            Reason:'已通过'
          }
          $.ajax({
            url: `${DomainName}/getEditAction?token=${$.cookie("token")}`,
            type: 'POST',
            data:{ Data: JSON.stringify({ 
              Modify: { order_financing_info: [_this.data] },
              Add: {order_financing_contract:[_this.form], order_financing_log:[obj]}
            })},
            success: function (res) {
              if (res.Status === 'success') {
                _this.$message.success("提交成功")
                window.history.go(-1)
              } else {
                _this.$message.error("提交失败，请稍后再试")
              }
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    onSerach() {				//查询方法
      console.log("搜搜")
    },
    addContract() {
      console.log("跳转")
    },
    back(){
      window.location.href = 'Orderfinancing.html'
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  },
})